package com.hl.mapper;

import com.hl.entity.College;
import com.hl.entity.Teacher;
import com.hl.entity.TeacherAndCollege;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * mybatis注解开发
 */
//
public interface TeacherNoteMapper {
    @Select("select * from teacher")
    List<Teacher> selectAllTeachers();

    @Select("select * from teacher where tid = #{tid}")
    Teacher selectTeacherById(int tid);

    @Delete("delete from teacher where tid = #{tid}")
    int deleteTeacherById(int tid);

    @Update("update teacher set tname = #{tname} where tid = #{tid}")
    int updateTeacherById(Teacher teacher);

    @Insert("insert into teacher(tname,college_id) values(#{tname},#{collegeId})")
    int addTeacher(Teacher teacher);

    @Select("select tid,tname,t.college_id,college_name from teacher t , college c where t.college_id = c.college_id")
    List<TeacherAndCollege> selectTeacherAndCollege();


    @Select("select * from teacher")
    @Results({
            @Result(column = "tid", property = "tid"),
            @Result(column = "tname", property = "tname"),
            @Result(column = "college_id", property = "collegeId"),
            @Result(property = "college",javaType = College.class,column="college_id",
                one = @One(select = "com.hl.mapper.CollegeMapper.selectCollegeById")
            )
    })
    List<Teacher> selectTeacherAndCollege2();

    @Select("select * from teacher")
    @Results({
            @Result(column = "tid", property = "tid"),
            @Result(column = "tname", property = "tname"),
            @Result(column = "college_id", property = "collegeId"),
            @Result(property = "courses" ,column = "tid",
                many = @Many(select = "com.hl.mapper.CourseMapper.selectCourseById")
            )
    })
    List<Teacher> selectTeacherAndCourse();

}
